package com.overlook.somniferous.common.util;

import com.overlook.somniferous.common.Enum.IResponseEnum;
import com.overlook.somniferous.common.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.Objects;

@Component
@Slf4j
public abstract class Assert {
    public static void nonNull(Object o, IResponseEnum responseEnum) {
        if (Objects.nonNull(o)) {
            log.info("{} is null", o);
            throw new BusinessException(responseEnum);
        }
    }

    public static void isBlank(String str, IResponseEnum responseEnum) {
        if (StringUtils.isBlank(str)) {
            log.info("{} is blank", str);
            throw new BusinessException(responseEnum);
        }
    }

    public static void isTrue(boolean bol, IResponseEnum responseEnum) {
        if (bol) {
            log.info("{} is true", bol);
            throw new BusinessException(responseEnum);
        }
    }
}
